<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
     async函数返回值:
     - async函数返回一个promise实例,默认是pending状态
     - 当async函数全部执行完成,async函数返回成功的promise实例,值为async函数的返回值
     - 当async函数内部有错误,则直接停止函数内代码的运行,直接返回失败的promise实例,值为错误信息
     - 当await等待的promise实例变成失败状态,则async函数的返回值和这个失败的promise实例保持一致,并停止函数内代码的运行
     - 当async内部return是promise实例的时候,async函数的返回值和这个promise实例保持一致

   await返回值:
     就是等待的promise实例成功状态的值
 */
        async function getData() {
            console.log("start");
            const awaitResult = await new Promise((resolve, reject) => {
                try {
                    // throw new Error("失败")
                    setTimeout(() => {
                        console.log("计时器");
                        resolve("数据");
                    }, 1000);
                } catch (e) {
                    reject(e.message)
                }
            });

            console.log("awaitResult", awaitResult);
            // throw new Error("失败")

            console.log("等计时器后的语句");

            return 1;
            // return Promise.resolve(1)
            // return Promise.reject(1);
        }

        const result = getData();
        console.log("result", result);
        console.log("end");
    </script>
</body>

</html>